{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# Notebook Code Cells\n",
        "\n",
        "This notebook is primarily going to cover scenarios that are different in Notebooks - like updating output, referencing NuGets, etc...  \n",
        "\n",
        "To learn C#  - Check our C# 101 series -  [First Module - Hello World](https://ntbk.io/csharp101-notebook01)!"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### Referencing NuGets"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 1,
      "metadata": {
        "dotnet_interactive": {
          "language": "csharp"
        }
      },
      "source": [
        "#r \"nuget:System.Text.Json\""
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": "<div><div></div><div></div><div><strong>Installed Packages</strong><ul><li><span>System.Text.Json, 6.0.4</span></li></ul></div></div>"
          },
          "execution_count": 1,
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "For additional details checkout - [Nuget Overview](https://github.com/dotnet/interactive/blob/main/docs/nuget-overview.md)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Referencing Assemblies"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 1,
      "metadata": {
        "dotnet_interactive": {
          "language": "csharp"
        }
      },
      "source": [
        "#r \"<path to .dll>\""
      ],
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Display and Update Values"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "For displaying values you have a few options.\n",
        "\n",
        "### Console.WriteLine\n",
        "\n",
        "Yes it works! You can use Console.WriteLine just like a console application and the output will be displayed."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 1,
      "metadata": {
        "dotnet_interactive": {
          "language": "csharp"
        }
      },
      "source": [
        "Console.WriteLine(\"Hello Console.WriteLine\");"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": "Hello Console.WriteLine\r\n"
          },
          "execution_count": 1,
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### Value on last line\n",
        "If the last line of a cell is variable, object, or literal- it's value will be displayed as output."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 1,
      "metadata": {
        "dotnet_interactive": {
          "language": "csharp"
        }
      },
      "source": [
        "\"This will work!\""
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": "This will work!"
          },
          "execution_count": 1,
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 1,
      "metadata": {
        "dotnet_interactive": {
          "language": "csharp"
        }
      },
      "source": [
        "var x =  \"This will work too\";\n",
        "x"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": "This will work too"
          },
          "execution_count": 1,
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### Built in \"Display\" function\n",
        "The display function is another alternative and it allows you to update displayed values. This is a great way to display and update information during long running tasks."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 1,
      "metadata": {
        "dotnet_interactive": {
          "language": "csharp"
        }
      },
      "source": [
        "var displayedValue = 0.Display();\n",
        "\n",
        "for (int x = 0; x<=10; x++)\n",
        "{\n",
        "\tawait Task.Delay(1000);\n",
        "\tdisplayedValue.Update(x);\n",
        "}"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/html": "<div class=\"dni-plaintext\">10</div>"
          },
          "execution_count": 1,
          "metadata": {}
        }
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": ".NET (C#)",
      "language": "C#",
      "name": ".net-csharp"
    },
    "language_info": {
      "file_extension": ".cs",
      "mimetype": "text/x-csharp",
      "name": "C#",
      "pygments_lexer": "csharp",
      "version": "8.0"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 4
}